
import { axiosInstance } from '../utils/request'
const userInfo = JSON.parse(localStorage.getItem('user'))
//登录
export const login = (data) => {
    return axiosInstance.post('/login', data, { headers: { 'content-type': 'application/x-www-form-urlencoded' } });
}

//获取访问次数
export const getDataNumberApi = () => {
    return axiosInstance.get(`/index/${userInfo.username}`, { headers: { 'Authentication': localStorage.token } })
}

//修改用户数据
export const changeUserDataApi = (data) => {
    return axiosInstance.put('/user/profile', data, { headers: { 'Authentication': localStorage.token } })
}

//重新获取用户数据
export const getUserDataApi = () => {
    return axiosInstance.get(`/user/${userInfo.username}`, { headers: { 'Authentication': localStorage.token } })
}

//图片修改
export const changeImgApi = (data) => {
    return axiosInstance.put('/user/avatar', data, { headers: { 'Authentication': localStorage.token } })
}

//获取用户
export const getAllUserDataApi = (data) => {
    return axiosInstance.get(`/user?${data}`, { headers: { 'Authentication': localStorage.token } })
}

//新增用户
export const addUserApi = (data) => {
    return axiosInstance.post('/user', data, { headers: { "Content-Type": "application/x-www-form-urlencoded", 'Authentication': localStorage.token } })
}

//修改用户
export const changeUserApi = (data) => {
    return axiosInstance.put('/user', data, { headers: { 'Authentication': localStorage.token } })
}

//删除用户
export const delUserApi = (data) => {
    return axiosInstance.delete(`/user/${data}`, { headers: { 'Authentication': localStorage.token } })
}

// 密码复核
export const checkPassApi = (data) => {
    return axiosInstance.get(`/user/password/check?${data}`, { headers: { 'Authentication': localStorage.token } })
}

// 修改密码
export const changePassApi = (data) => {
    return axiosInstance.put('/user/password', data, { headers: { 'Authentication': localStorage.token } })
}